package pushe.qiongyou;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;

import java.util.ArrayList;

import SQJavaBean.FirstSQshouye;

/**
 * Created by Administrator on 2015/4/25.
 */
public class MyGirdViewAdapter extends BaseAdapter {

//  String A[]={"最近","最近","最近","最近","最近","最近","最近","最近"};
    private LayoutInflater inflater;
    private ViewHolder holder;
    private ArrayList<FirstSQshouye> fs;
    private Context context;

    public MyGirdViewAdapter(ArrayList<FirstSQshouye> fs,Context context) {
        this.fs=fs;
        this.context=context;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if(fs!=null){
            return fs.size();
        }
        return 0;
    }

    @Override
    public FirstSQshouye getItem(int position) {
        return fs.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            holder =new ViewHolder();
            convertView=inflater.inflate(R.layout.item_she_qu,null);
            holder.imageView= (ImageView) convertView.findViewById(R.id.sq_image);
            holder.name= (TextView) convertView.findViewById(R.id.sq_name);
            holder.theme= (TextView) convertView.findViewById(R.id.sq_theme);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.imageView.setImageResource(R.drawable.ic_launcher);
        BitmapUtils bitmapUtils=new BitmapUtils(context);
        bitmapUtils.display(holder.imageView,fs.get(position).getPhoto());
        holder.name.setText(fs.get(position).getName());
        holder.theme.setText(fs.get(position).getTotal_threads()+"个主题");
        return convertView;
    }
    class ViewHolder{
        private ImageView imageView;
        private TextView name;
        private TextView theme;
    }
}
